package gui.tableModel;

import java.util.Date;
import java.util.List;

import javax.swing.table.AbstractTableModel;

import valueobjects.Azubi.Azubi;

public class TableModelAzubi extends AbstractTableModel {

	List<Azubi> listAzubi;

	public TableModelAzubi() {

	}

	public List<Azubi> getListAzubi() {
		return listAzubi;
	}

	public void setListAzubi(List<Azubi> listAzubi) {
		this.listAzubi = listAzubi;
		super.fireTableDataChanged();
	}

	public Class<?> getColumnClass(int col) {
		switch (col) {
		case 0:
			return Integer.class;
		case 1:
			return String.class;
		case 2:
			return String.class;
		case 3:
			return String.class;
		case 4:
			return Integer.class;
		case 5:
			return String.class;
		case 6:
			return String.class;
		case 7:
			return String.class;
		case 8:
			return String.class;
		case 9:
			return String.class;
		case 10:
			return Date.class;
		case 11:
			return Date.class;
		case 12:
			return Date.class;

		default:
			throw new IllegalArgumentException();
		}
	}

	public int getColumnCount() {
		return 13;
	}

	public String getColumnName(int col) {
		switch (col) {
		case 0:
			return "Azubi_ID";
		case 1:
			return "Name";
		case 2:
			return "Vorname";
		case 3:
			return "Vorwahl";
		case 4:
			return "Telefon";
		case 5:
			return "Email";
		case 6:
			return "Ausbilder_Name";
		case 7:
			return "Betrieb";
		case 8:
			return "Klasse";
		case 9:
			return "Beruf";
		case 10:
			return "Geburtsdatum";
		case 11:
			return "Eintrittsdatum";
		case 12:
			return "Austrittsdatum";
		default:
			throw new IllegalArgumentException();
		}

	}

	public int getRowCount() {
		if (listAzubi == null) {
			return 0;
		} else {
			return listAzubi.size();
		}
	}

	public Object getValueAt(int row, int col) {
		switch (col) {
		case 0:
			return listAzubi.get(row).getId();
		case 1:
			return listAzubi.get(row).getName();
		case 2:
			return listAzubi.get(row).getVorname();
		case 3:
			return listAzubi.get(row).getVorwahl();
		case 4:
			return listAzubi.get(row).getTelefon();
		case 5:
			return listAzubi.get(row).getEmail();
		case 6:
			return listAzubi.get(row).getAusbilder().getName();
		case 7:
			return listAzubi.get(row).getAusbilder().getBetrieb()
					.getBezeichnung();
		case 8:
			return listAzubi.get(row).getKlasse().getId();
		case 9:
			return listAzubi.get(row).getBeruf();
		case 10:
			return listAzubi.get(row).getGeburtsdatum();
		case 11:
			return listAzubi.get(row).getEintrittsdatum();
		case 12:
			return listAzubi.get(row).getAustrittsdatum();

		default:
			throw new IllegalArgumentException();
		}
	}

	public Azubi getSelectedModel(int index) {
		return this.listAzubi.get(index);
	}
}
